import logging
import requests
from api.reg_login_api import RegLoginApi
from config import BASE_HOST


class RechargeApi:
    def __init__(self, session):
        # 接收session对象的变量
        self.ses = session

    # 获取充值验证码接口
    def get_recharge_verify_code(self, r):
        resp = self.ses.get(url=BASE_HOST + "/common/public/verifycode/{}".format(r))
        logging.info("获取图片验证码接口的响应状态码{}".format(resp.status_code))
        return resp

    # 充值接口
    def recharge(self, amount, img_code, paymentType="chinapnrTrust", formStr="reForm"):
        form_dict = {"paymentType": paymentType,
                     "amount": amount,
                     "formStr": formStr,
                     "valicode": img_code}
        resp = self.ses.post(url=BASE_HOST + "/trust/trust/recharge", data=form_dict)
        logging.info("充值接口响应数据：{}".format(resp.json()))
        return resp

    # 第三方充值接口
    def third_recharge(self, url, form_dict):
        resp = self.ses.post(url=url, data=form_dict)
        logging.info("第三方充值接口响应数据：{}".format(resp.text))
        return resp


if __name__ == '__main__':
    ses = requests.session()
    recharge = RechargeApi(ses)
    login = RegLoginApi(ses)
    login.user_login("13155552220", "qq1234")
    resp = recharge.get_recharge_verify_code(0.023537996035404962)
    # form_data = {"paymentType": "chinapnrTrust",
    #              "amount": "100000",
    #              "formStr": "reForm",
    #              "valicode": "8888"}
    resp = recharge.recharge(10000, 8888)
    print(resp.json())
